package com.shutong.edu.invoke.retry.handler;

import com.shutong.edu.invoke.retry.model.RetryInfo;
import com.shutong.edu.invoke.retry.processor.JdkProxyRetryProcessor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 *
 * @ClassName: RetryJdkProxyHandler.java
 * @author: Naughty Guo
 * @date: Jun 2, 2016
 */
public class RetryJdkProxyHandler implements InvocationHandler {

    private Object targetObject;

    public RetryJdkProxyHandler(Object targetObject) {
        this.targetObject = targetObject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        RetryInfo retryInfo = new RetryInfo();
        retryInfo.setTargetMethod(method);
        retryInfo.setTargetProxyObject(targetObject);
        retryInfo.setTargetOriginalObject(targetObject);
        retryInfo.setArguments(args);
        return new JdkProxyRetryProcessor().retryProcess(retryInfo);
    }
}
